package com.yc.chaoshi.cs_index.web;



import com.yc.chaoshi.cs_index.web.feign.IOrderAction;
import com.yc.chaoshi.cs_index.web.feign.IUserAction;
import com.yc.chaoshi.entity.PmsGoods;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@RestController
public class IndexAction {

    @Resource
    IOrderAction iorderAction;

    //默认地址
    @GetMapping("/")
    ModelAndView index(ModelAndView mav){
        mav.setViewName("index"); // 请求转发
        mav.addObject("fenleis",iorderAction.queryFenlei1());
        return mav;
    }

    @GetMapping("/{page}.htm")
    ModelAndView toGage(@PathVariable String page, ModelAndView mav){
        mav.setViewName(page);
        return mav;
    }

    @GetMapping("/search?{name}")
    ModelAndView search(@PathVariable String name,
                        @RequestParam(defaultValue = "1") int page,
                        @RequestParam(defaultValue = "16") int size,
                        ModelAndView mav){
        mav.setViewName("search"); // 请求转发
        mav.addObject("fenleis",iorderAction.queryFenlei1());
        mav.addObject("QGoods",iorderAction.queryGoods(name,page,size));
        mav.addObject("name",name);
        return mav;
    }


    @GetMapping("/list1_{aid}")
    ModelAndView list1(@PathVariable int aid,
                       @RequestParam(defaultValue = "1") int page,
                       @RequestParam(defaultValue = "16") int size,
                       ModelAndView mav){
        mav.setViewName("list1");
        mav.addObject("fenleis",iorderAction.queryFenlei1());
        mav.addObject("apage",iorderAction.queryPageByAid(aid,page,size));
        mav.addObject("Aname",iorderAction.findByAId(aid));/*通过aid查表fenlei1*/
        mav.addObject("AllFl",iorderAction.queryAll1(aid));/*aid查联表fenlei123*/
        return mav;
    }

    @GetMapping("/list2_{bid}")
    ModelAndView list2(@PathVariable int bid,
                       @RequestParam(defaultValue = "1") int page,
                       @RequestParam(defaultValue = "16") int size,ModelAndView mav){
        mav.setViewName("list2");
        mav.addObject("fenleis",iorderAction.queryFenlei1());
        PmsGoods goods=iorderAction.findByBId(bid);
        mav.addObject("Aname",iorderAction.findByAId(goods.getAid()));
        mav.addObject("Bname",goods);/*通过bid查表fenlei2*/
        mav.addObject("bpage",iorderAction.queryPageByBid(bid,page,size));
        mav.addObject("AllFl",iorderAction.queryAll1(goods.getAid()));/*aid查联表fenlei123*/
        mav.addObject("AllFl2",iorderAction.queryAll2(bid));/*bid查联表fenlei23*/
        return mav;
    }

    @GetMapping("/list3_{cid}")
    ModelAndView list3(@PathVariable int cid,
                       @RequestParam(defaultValue = "1") int page,
                       @RequestParam(defaultValue = "16") int size,ModelAndView mav){
        mav.setViewName("list3");
        mav.addObject("fenleis",iorderAction.queryFenlei1());
        PmsGoods goodCs=iorderAction.findByCId(cid);
        PmsGoods goodBs=iorderAction.findByBId(goodCs.getBid());
        mav.addObject("Aname",iorderAction.findByAId(goodBs.getAid()));/*通过bid查表fenlei1*/
        mav.addObject("Bname",goodBs);/*通过bid查表fenlei2*/
        mav.addObject("Cname",goodCs);/*通过cid查表fenlei3*/
        mav.addObject("cpage",iorderAction.queryPageByCid(cid,page,size));
        mav.addObject("AllFl",iorderAction.queryAll1(goodBs.getAid()));/*aid查联表fenlei123*/
        mav.addObject("AllFl2",iorderAction.queryAll2(goodCs.getBid()));/*bid查联表fenlei23*/
        mav.addObject("AllFl3",iorderAction.queryAll3(cid));/*cid查联表fenlei3*/
        return mav;
    }

    @GetMapping("/info_{id}")
    ModelAndView toPage(@PathVariable int id,ModelAndView mav){
        mav.setViewName("info");
//        mav.addObject("cates",orderAction.queryCategoryAll());
        mav.addObject("fenleis",iorderAction.queryFenlei1());
        PmsGoods pmsGoods=iorderAction.findById(id);
        PmsGoods goodCs=iorderAction.findByCId(pmsGoods.getOid());
        PmsGoods goodBs=iorderAction.findByBId(goodCs.getBid());
        mav.addObject("Aname",iorderAction.findByAId(goodBs.getAid()));/*通过bid查表fenlei1*/
        mav.addObject("Bname",goodBs);/*通过bid查表fenlei2*/
        mav.addObject("Cname",goodCs);/*通过cid查表fenlei3*/
        mav.addObject("goods",pmsGoods);/*id查goods表*/
        mav.addObject("AllFl2",iorderAction.queryAll2(goodCs.getBid()));/*bid查联表fenlei23*/
        return mav;
    }

    @GetMapping("/search?{name}")
    ModelAndView search(@PathVariable String name,
                        @RequestParam(defaultValue = "1") int page,
                        @RequestParam(defaultValue = "16") int size,
                        ModelAndView mav){
        mav.setViewName("search"); // 请求转发
        mav.addObject("fenleis",iorderAction.queryFenlei1());
        mav.addObject("QGoods",iorderAction.queryGoods(name,page,size));
        mav.addObject("name",name);
        return mav;
    }


    @GetMapping("/list1_{aid}")
    ModelAndView list1(@PathVariable int aid,
                       @RequestParam(defaultValue = "1") int page,
                       @RequestParam(defaultValue = "16") int size,
                       ModelAndView mav){
        mav.setViewName("list1");
        mav.addObject("fenleis",iorderAction.queryFenlei1());
        mav.addObject("apage",iorderAction.queryPageByAid(aid,page,size));
        mav.addObject("Aname",iorderAction.findByAId(aid));/*通过aid查表fenlei1*/
        mav.addObject("AllFl",iorderAction.queryAll1(aid));/*aid查联表fenlei123*/
        return mav;
    }

    @GetMapping("/list2_{bid}")
    ModelAndView list2(@PathVariable int bid,
                       @RequestParam(defaultValue = "1") int page,
                       @RequestParam(defaultValue = "16") int size,ModelAndView mav){
        mav.setViewName("list2");
        mav.addObject("fenleis",iorderAction.queryFenlei1());
        PmsGoods goods=iorderAction.findByBId(bid);
        mav.addObject("Aname",iorderAction.findByAId(goods.getAid()));
        mav.addObject("Bname",goods);/*通过bid查表fenlei2*/
        mav.addObject("bpage",iorderAction.queryPageByBid(bid,page,size));
        mav.addObject("AllFl",iorderAction.queryAll1(goods.getAid()));/*aid查联表fenlei123*/
        mav.addObject("AllFl2",iorderAction.queryAll2(bid));/*bid查联表fenlei23*/
        return mav;
    }

    @GetMapping("/list3_{cid}")
    ModelAndView list3(@PathVariable int cid,
                       @RequestParam(defaultValue = "1") int page,
                       @RequestParam(defaultValue = "16") int size,ModelAndView mav){
        mav.setViewName("list3");
        mav.addObject("fenleis",iorderAction.queryFenlei1());
        PmsGoods goodCs=iorderAction.findByCId(cid);
        PmsGoods goodBs=iorderAction.findByBId(goodCs.getBid());
        mav.addObject("Aname",iorderAction.findByAId(goodBs.getAid()));/*通过bid查表fenlei1*/
        mav.addObject("Bname",goodBs);/*通过bid查表fenlei2*/
        mav.addObject("Cname",goodCs);/*通过cid查表fenlei3*/
        mav.addObject("cpage",iorderAction.queryPageByCid(cid,page,size));
        mav.addObject("AllFl",iorderAction.queryAll1(goodBs.getAid()));/*aid查联表fenlei123*/
        mav.addObject("AllFl2",iorderAction.queryAll2(goodCs.getBid()));/*bid查联表fenlei23*/
        mav.addObject("AllFl3",iorderAction.queryAll3(cid));/*cid查联表fenlei3*/
        return mav;
    }

    @GetMapping("/info_{id}")
    ModelAndView toPage(@PathVariable int id,@RequestParam(defaultValue = "1") int page,ModelAndView mav){
        mav.setViewName("info");
//        mav.addObject("cates",orderAction.queryCategoryAll());
        mav.addObject("fenleis",iorderAction.queryFenlei1());
        PmsGoods pmsGoods=iorderAction.findById(id);
        PmsGoods goodCs=iorderAction.findByCId(pmsGoods.getOid());
        PmsGoods goodBs=iorderAction.findByBId(goodCs.getBid());
        mav.addObject("Aname",iorderAction.findByAId(goodBs.getAid()));/*通过bid查表fenlei1*/
        mav.addObject("Bname",goodBs);/*通过bid查表fenlei2*/
        mav.addObject("Cname",goodCs);/*通过cid查表fenlei3*/
        mav.addObject("goods",pmsGoods);/*id查goods表*/
        mav.addObject("AllFl2",iorderAction.queryAll2(goodCs.getBid()));/*bid查联表fenlei23*/
        mav.addObject("pl",iorderAction.findPl(id,page));
        mav.addObject("id",id);
        return mav;
    }
}
